/*
 * refactor by Wind and Yuntao 20100913
 */
var RTQ_Quicktake = function(callback){
	this.callback=callback;//add by yuntao
    this.ticker = null;//current ticker
    this.tickerType = null;//current ticker type
    this.tabId = null;//current tab id    
    this.subTabId = null;//current subtab id
    this.detail = true;//in SR or in Detail window
    this.showTab = true;//show tab or not
    this.tabMapping={
		'Operation':{'FE':3.26,'FO':3.26,'FC':3.32},
		'Ratings & Risk':{'FE':3.23,'FO':3.23,'FC':3.35},
		'Portfolio':{'FE':3.25,'FO':3.25,'FC':3.36},
		'Shareholders':{'ST':3.15,'FE':3.15,'FO':3.15,'FC':3.15},
		'Filings':{'ST':3.17,'FE':3.27,'FO':3.27,'FC':3.27},
		'Performance':{'ST':3.21,'FE':3.28,'FO':3.21,'FC':3.34}
	};
    this.config = {};//config
    this.region = 'USA';
    this.cId = '';
    this.secId = '';
    this.pId = null;
    this.gKey = null;
    this.currency = 'USD'; 
    this.curIframe = null;//current iframe;
    this.iframebg = {'default':'#fff','black':'#1c1c1c','gray':'#fff'};
    this.$mainWrap = null; 
    this.$subTab = null;
    this.$subWrap = null;
	this.$mainWrapHeight=28;
	this.$subWrapHeight=28;
    this.$moreBtn = null;
	this.$loading = null;
	this.interval = null;
	this.i = 0;
};
RTQ_Quicktake.prototype = {
	init: function(Cfg, Sid, ContainerId, objStr, pCfg){
		var self = this;
		//extend config
		this.id = Sid;
		if (Cfg) {
			$.extend(this.config, Cfg);
			if (Cfg.ticker) {
				this.ticker = Cfg.ticker;
			}
			if (Cfg.securityType || Cfg.tickerType) {
				this.tickerType = Cfg.securityType || Cfg.tickerType;
			}
			if (Cfg.tab) {
				this.tabId = this._getOldQtPage(Cfg.tab)[0];
			}
			if (Cfg.subtab) {
				this.subTabId = this._getOldQtPage(Cfg.tab, Cfg.subtab)[1];
			}
			this.detail = Cfg.detail === false ? false : true;
			this.showTab = Cfg.showTab === false ? false : true;
		};
		//generate DOM
		this.container = $('#' + ContainerId);
		this.HTML = '<div class="rtq-quicktake">' +
						'<div class="hd">'+
							'<div class="tabmenu"></div>'+
							'<div class="rtq-qt-sm" style="border-bottom:1px solid #999;position:absolute;z-index:80;width:100%;height:'+this.$subWrapHeight+'px;">'+
								'<div class="subtabmenu"></div>'+
								'<a href="#" class="rtq-qt-more" style="position:absolute;bottom:8px;right:8px;">more...</a>'+
							'</div>'+
						'</div>' +
						'<div class="ft"></div>' +
						'<div class="nodata">This window only supports Stock, Closed-end Fund(CE), Exchange Trade Fund(ETF), Mutual Fund(FO) in the QuoteSpeed 2.0</div>' +
					'</div>';
		this.el = $(this.HTML);
		this.el.appendTo(this.container);		
		//generate TabMenu
		this.tabMenu = new Util.TabMenu($('.tabmenu', this.el)[0], [], {
			onActive: function(tab){
                RTQ_Quicktake.currentId = self.id;
				self.tabId = self.tabMenu.cfg.activeTabId = tab.id;
				if ($('iframe', tab.panel).length > 0) {
					self.curIframe = tab.panel.find('iframe');
				}
				else {
					self.curIframe = $('<iframe id="rtq-qt-frm-' + self.id + '-' + tab.id + '" name="rtq-qt-frm-' + self.id + '-' + tab.id + '" style="border:none;margin:'+self.$subWrapHeight+'px 0 0 0;background:'+ self.iframebg[QS_Theme] +';" frameborder="0" src="" class="rtq-qt-ifm"></iframe>').appendTo(tab.panel);
				}
				self._reBindData(tab);
				if (!tab.subTab && self.ticker != null && typeof(self.ticker) != 'undefined') {
					self._sendRequest(tab);
				}
				
				self.changeOutSize(null, null, 1);
				self._changeMode();
				//	if(tab.id=='3.24'){self.curIframe.css({'overflowX':'hidden'})}
				
//				self.subTabMenu.currentTab = null;
			}
		}, {
			width: 100,
			isExcuteCallbackAtInit: true,
			autoResize: false,
			tabsList: true,
			activeTabId: self.tabId + ''
		});
		this.subTabMenu = new Util.TabMenu($('.subtabmenu', this.el)[0], [], {
			onActive: function(tab){
				RTQ_Quicktake.currentId = self.id;
				self.subTabId = self.subTabMenu.cfg.activeTabId = tab.id;
				self.changeOutSize(null, null, 2);
				if (self.ticker != null && typeof(self.ticker) != 'undefined') {
					self._sendRequest(tab);
				}
			}
		}, {
			width: 95,
			isExcuteCallbackAtInit: true,
			autoResize: true,
			tabsList: true,
			autoFixtoText: true,
			activeTabId: self.subTabId + ''
		});
		this.$mainWrap = this.el.find('.tabmenu .rtq-tab-wrap');
		this.$subTab = this.el.find('.subtabmenu');
		this.$subWrap = this.el.find('.subtabmenu .rtq-tab-wrap');
		this.$moreBtn = this.el.find('.rtq-qt-more');
		this.$noData = this.el.find('.nodata');
		this.$mainWrapHeight = this.$mainWrap.height();
		this.$subWrapHeight = $('.rtq-qt-sm').height();
		this.el.find('.rtq-qt-sm').css({top:this.$mainWrapHeight});
		//generate setting panel
		this.createSettingPn();
		//get data of tabmenu
		if (!this.ticker) {
			this._reBindData();
		}
		else {
			this.acceptTicker(this.ticker);
		}
		this._showHideTab();
		if (this.hasSearch) {
			this.initAutoComplete();
		}
		
		//generate cookie
		//        document.cookie='mstar=V6314P49NN4O621LKMM0PMK8NP113LL0M020772M84LM25443L8L2N73M86ON884M8997O6317N462N1871NMLL05M8432OPMP3660K1L8P4O85O6P2O4N9NKO0P7K4KLLOOO1N4O4O5963LN6K6ON2M2M936O0712813DC8337DC37BE2C121EBC63C7F1F51;.ASPXAUTH=741AA11ECC3C40708B92BCE37F556F77D89AC0D61F80144A9B34412B36D0413B6BE360598CFC9B031EEBDF9479A93461F70BFDAA4F1BD3E23A622CE0F110409FB849D4C372CCBA60A5C09EEB4D0B3E7D;path=/;domain=.morningstar.com';  
		this.SetCookie("QS_SRT_VRF",this.generateSRT(),30);
	},
	QueryString: function(item){
		var svalue = location.search.match(new RegExp('[\?\&]' + item + '=([^\&]*)(\&?)', 'i'));
		return svalue ? svalue[1] : "";
	},
    _getOldQtPage:function(code,subcode){
        var Code_array = [];
        var oldMapping={
            0:{3.11:{}},
            1:{3.12:{0:3.1211,1:3.1212,2:3.1213}},
            2:{3.13:{0:3.1311,1:3.1312,2:3.1313,3:3.1314}},
            3:{3.14:{0:3.1411,1:3.1412}},
            4:{3.15:{0:3.1511,1:3.1512,2:3.1513,3:3.1514,4:3.1515}},
            5:{3.16:{0:3.1611,1:3.1612,2:3.1613,3:3.1614,4:3.1615,5:3.1616}},
            6:{3.17:{}},
            7:{3.18:{}},
            8:{3.19:{}},
            9:{3.21:{0:3.2111,1:3.2112,2:3.2113,3:3.2114,4:3.2115}},
            10:{3.22:{}},
            11:{3.23:{}},
            12:{3.24:{}}
        };
        var getCode=function(obj){
            var id;
            for(var o in obj){
                id = o;
                break;
            }
            return parseFloat(id,10);
        };
        var getSubCode=function(id,obj,subId){
            var SubId=obj[id][subId]||subId;
            return parseFloat(SubId,10);
        };
        if(typeof code!='undefined'){
            if(oldMapping[code]){
                Code_array[0]=getCode(oldMapping[code]);
            }else{
                Code_array[0]=code;
            }            
        }
        if(typeof subcode!='undefined'&&typeof code!='undefined'){
            if(oldMapping[code]){
                Code_array[1]=getSubCode(Code_array[0],oldMapping[code],subcode);
            }else{
                Code_array[1]=subcode;
            }            
        }else{
            Code_array[1]=subcode;
        }
        if(Code_array.length==0){
            Code_array=[];            
        }
        return Code_array;
    },
    _showHideTab:function(){		
        if(this.showTab==false){  
			this.$mainWrap.css({visibility:'hidden',height:0});                
            this.$subTab.parent().css({top:0});
        }else{
			this.$mainWrap.css({visibility:'visible',height:this.$mainWrapHeight});                   
            this.$subTab.parent().css({top:this.$mainWrapHeight});
            this.tabMenu.showActiveTab();
        }
        this.changeOutSize(null,null,3);
    },
    _getTabTxt:function(id){
        return QS_QT_TabMapping[id].txt;
    },
    _changeMode:function(){
        if(this.detail==true){
            var ticker = this.ticker==null?'':this.ticker.split(':')[1];
			var title;
			if (ticker != '') {
				title = this._getTabTxt(this.tabId) + ':';
			}
			else {
				if (typeof this.config.title != 'undefined' && typeof this.config.title.txt != 'undefined' && this.config.title.txt != '') {
					title = this.config.title.txt;
				}
				else {
					title = 'Quicktake:';
				}
			}
			if(typeof this.setTitle=='function'){this.setTitle(title, ticker);}
			this.$moreBtn.hide();
		}
	},
	checkSecurityModule: function(id, tabData, oData, tabMapping){
		if (QS_SMC.checkSecurityModule(this.tickerType || 'ST', parseFloat(id, 10))) {
			if (!this.tabId) {
				this.tabId = id;
			}
			tabData = tabMapping[id];
			oData.push({
				id: id,
				txt: tabData['txt'],
				val: tabData['val'],
				url: tabData['url'],
				par: tabData['par'],
				subTab: tabData['subTab'] || null,
				statc: tabData['statc'] || false,
				closable: false
			});
		}
	},
	_reBindData: function(tab){
		var oData = [], tabData, tabMapping;
		if (typeof tab == 'undefined') {
			tabMapping = QS_QT_TabMapping;
			var sequence = QS_QT_TabSequence[this.tickerType || 'ST'];
			for (var idx = 0; idx < sequence.length; idx++) {
				var id = sequence[idx];
				if (!tabMapping[id]) 
					continue;
				this.checkSecurityModule(id, tabData, oData, tabMapping);
			}
		}
		else {
			tabMapping = QS_QT_TabMapping[tab.id]['subTab'] || {};
			for (var id in tabMapping) {
				this.checkSecurityModule(id, tabData, oData, tabMapping);
			}
		}
		this._reBindTabMenu(oData, tab);
	},
	_reBindTabMenu: function(oData, tab){
		if (typeof tab == 'undefined') {
			this.tabMenu.reBindData(oData);			           
		}else{
			if (oData.length > 0) {
				this.$subTab.show();
				this.subTabMenu.reBindData(oData);
				this.curIframe.css({
					marginTop: this.$subWrapHeight
				});
				this.$subTab.parent().show();
				this.curIframe.TOP = 0;
			}else{//if no data for subtabmenu, hide it
				var x=this.detail?0:this.$subWrapHeight;
				this.$subTab.hide();
				this.curIframe.css({
					marginTop: x
				});
				if(this.detail==true){
					this.$subTab.parent().hide();
				}
				
				this.curIframe.TOP = this.$subWrapHeight;
			}
		}
	},
	_getParameter: function(par){
		var temp, parameter = '';
		for (var i = 0, l = par.length; i < l; i++) {
			temp = par[i];
			for (var o in temp) {
				if (temp[o] == 'TICKER') {
					parameter += "&t=" + this.ticker || '';
				}
				else 
					if (temp[o] == 'ticker') {
						if (this.ticker) {
							var temp = this.ticker.split(':');
							parameter += "&t=" + (temp[1] || '') + "&exch=" + (temp[0] || '');
						}
						else {
							parameter += "&t=";
						}
					}
					else {
						if (!this.gKey) {
							continue;
						}
						parameter += "&" + o + "=" + gData[this.gKey][temp[o]] || '';
					}
			}
		}
		
	    parameter +="&theme="+(QS_Theme||'default')+"&qt_version="+(QS_VERSION||'dev')+"&tickerType="+ this.tickerType;
        return parameter;
    },
	_send:function (tab){
		if (tab.id != this.tabId && (tab.id + '').indexOf(this.tabId + '') == -1) {
			return;
		}
        var u = '';
        u = tab.url + this._getParameter(tab.par) + '&detail=' + this.detail;
        u += "&qs_qt_module="+tab.id;
	   	if (tab.id == 3.1312 || tab.id == 3.1313 || tab.id == 3.1314) {
            u = u+'&statement='+this.QueryString('statement')+'&dataType='+this.QueryString('dataType')+'&period='+this.QueryString('period')+'&order='+this.QueryString('order')+'&View='+this.QueryString('View')+'&rounding='+this.QueryString('rounding');
        }
		
		if (tab.id == 3.1611 && this.region != 'USA') {
			u = this._getLinkToDataNoAvailable();
        }else if ((tab.id == 3.17 || tab.id == 3.27) && !gData[this.gKey]["companyId"]) {
			u = this._getLinkToDataNoAvailable();
		}
		
        if (this.curIframe.attr('src') != u) {
            this.curIframe.attr('src', u);
            this.loading('', 5000);
        }
   },
   _getLinkToDataNoAvailable: function(){
	   	var url = "//" + window.location.hostname;
	   	if (window.location.href.indexOf("/opt/") != -1) {
	   		url += "/opt";
	   	}
	   	else 
	   		if (window.location.href.indexOf("/prestage/") != -1) {
	   			url += "/prestage";
	   		}
	   	url = url + '/error_page.jsp?ErrorCode=1';
		return url;
   },
    _sendRequest:function(tab){
		var self = this;
		if(typeof(tab['statc'])!='undefined'&&tab['statc']==true){
			getStaticData([this.pId], function(){
				self._send(tab);
			});
		}else{
			self._send(tab);
		}
    },
    addTicker:function(ticker){
        var self = this;
//    	if (this.ticker != ticker) {
			//if(this.ticker){this.tValidation.unSubscribe([this.gKey]);}
			//this.ticker = ticker;		
			self.tValidation.showAlert = false;	
			self.tValidation.checkTickers(ticker,function(o,ft){
				if(o.length == 0&&ft.length!=0){
				    var ms = String.format(TEXT.TickerValidationNotFound, ft[0]);
					Util.alert(ms);
//					Util.alert("Data not available for this ticker.");
				}else if(o.length == 0&&ft.length==0){
					Util.alert("Data not available for this ticker.");	//"This widget don't support the type of this ticker."
				}else{
					self.validateCallback(o);
				}
			});			
//		}
//		else{
//			self.tValidation.checkTickers(ticker,function(o){
//				self.validateCallback(o);
//			});
//        }
    },
    acceptTicker:function(ticker){
        this.addTicker(ticker);
    },
    validateCallback: function(gkeyList){
		if (!gkeyList.length) {
			return;
		}
		var tlist = [];
		if(typeof(this.hideLoading) == 'function'&&typeof(gkeyList)!= 'undefined'&&gkeyList.length==0){
            this.hideLoading();
        }
        if(!gkeyList||!gkeyList.length)return;
		for(var i =0;i<gkeyList.length;i++){
			if(!gData[gkeyList[i]]["companyId"]){// no company Id
				tlist.push(gData[gkeyList[i]]["performanceId"]);	
			}
		}
		var self = this;
		if(tlist.length){
			$.getJSON(QS_PROTOCOL+"qt.morningstar.com/switchservice/getids.ashx?symbol=" + tlist.join(",")+ "&cb=?", function(o){
				var gkey;
				if(o.Records&&o.Records.length){
					for(var j=0;j<o.Records.length;j++){
						tenforInfo = o.Records[j].TenforeInfo;
						if (tenforInfo && tenforInfo.length > 1) {
		                    gkey = tenforInfo[1] + ":" + tenforInfo[0];
							if ((o.Records[j].Type != "XI"&&o.Records[j].Region.toUpperCase() == "USA") ||(o.Records[j].Type == "XI" && o.Records[j].TenforeInfo[1] <= 126)) {// USA sercurity
		                        gkey = "126:" + tenforInfo[0];
		                    }
							gData[gkey]["companyId"] = o.Records[j].CFID;
						}
					}
				}
				if (gData[gkeyList[0]]["mType"] == "ST") {//judge PR(Preferred Stock) when the security type is 'ST'
					getStaticData([gData[gkeyList[0]]["performanceId"]], function(o){
						self._validateCallBack(gkeyList);
					});
				} else {
					self._validateCallBack(gkeyList);
				}
			});
		}else if (gData[gkeyList[0]]["mType"] == "ST") {//judge PR(Preferred Stock) when the security type is 'ST'
			getStaticData([gData[gkeyList[0]]["performanceId"]], function(o){
//				var preferedType = gData[gkeyList[0]]['st816'];
//				if(typeof(preferedType)!='undefined' && preferedType == '02'){
//					self.mType = 'PR'
//				}
				self._validateCallBack(gkeyList);
			});
		}
		else {
			this._validateCallBack(gkeyList);
		}	
	},
	_validateCallBack: function(gkeyList){
	    var d;
		if(typeof(this.hideLoading) == 'function'&&typeof(gkeyList)!= 'undefined'&&gkeyList.length==0){
            this.hideLoading();
        }
		for (var i = 0, l = gkeyList.length; i < l; i++) {
			this.gKey = gkeyList[i];
			d = gData[this.gKey] ? gData[this.gKey] : gData[gIdMap[this.gKey]];
			if (d) {
				this.ticker = d.exch + ":" + d.ticker;
				this.region = d.country;
				this.cId = d.companyId || '';
				this.secId = d.secId || '';
				this.pId = d.performanceId;
				this.currency = d.currency;
				if (this.tickerType != d.mType) {
					if (this.tabMenu.currentTab) {
						this.tabMenu.cfg.activeTabId = (this.tabMapping[this.tabMenu.currentTab.txt] ||
						{})[d.mType] ||
						this.tabMenu.currentTab.id;
					}
					
					var currentTab = this.config.tab;
					var itm = null, flag = false;
					for (var mappings in this.tabMapping) {
						var item = this.tabMapping[mappings];
						for (var tickerType in item) {
							if (item[tickerType] == currentTab) {
								itm = item, flag = true;
								break;
							}
						}
						if (flag) 
							break;
					}
					
					if (itm != null) {
						this.tabMenu.cfg.activeTabId = itm[d.mType];
					}
				}
				if (this.tickerType != d.mType || !this.tabMenu.currentTab
					||(this.tickerType!='PR' && typeof(d["st816"])!='undefined' && d["st816"] == '02')) {//Preferred Stock
					this.tickerType = d.mType;
					if(typeof(d["st816"])!='undefined' && d["st816"] == '02'){
						this.tickerType = 'PR';
					}
					this._reBindData();
				}
				
				if (this.tabMenu.currentTab && (!this.subTabMenu.currentTab||typeof(QS_QT_TabMapping[this.tabMenu.currentTab.id]["subTab"])=="undefined")) {//have no subtab
					this.$noData.hide();
					this._sendRequest(this.tabMenu.currentTab);
				}
				else 
					if (this.subTabMenu.currentTab) {
						this.$noData.hide();
						this._sendRequest(this.subTabMenu.currentTab);
					}
				if (!this.tabMenu.currentTab) {
					this.subTabMenu.reBindData([]);
					this.$noData.show();
				}
				this._changeMode();
				//this.changeOutSize(); 
				if (typeof(this.callback) != 'undefined' &&
					typeof this.callback.afterAcceptTicker == 'function') {
					// call the afterAcceptTicker, add by yuntao
					this.callback.afterAcceptTicker(this.gKey);
				}
			}
			break;
		}
	},
	loading:function(callback,duration){
		var self=this;
		this.showLoading(false);
		if(typeof callback == 'function'){
            callback();
        }
		var loadingtime = 6000;
		if(typeof duration != 'undefined'){
			loadingtime = parseInt(duration,10);
		}
		var hideLoading = setTimeout(function(){self.hideLoading();},loadingtime);
		//clearTimeout(hideLoading);
	},
    getSettingPanelDOM:function(){
        if(this.$settingMenu!=null){
            return settingPanelDOM = this.$settingMenu[0];
        }        
    },
    createSettingPn:function(){
        var self=this;	
        this.$settingMenu = $('<ul><li class="showtab"></li></ul>');
        
        var chkObj = new Util.SelectButton(this.$settingMenu.find('.showtab'), {txt:'Show Quicktake tab menu',val:''}, {
            onClick: function(v){                
                if(chkObj.isSelected){
                    self.showTab=true;
                }else{
                    self.showTab=false;
                }
                self._showHideTab();
            }
        },{type:'checkbox'});
        
        if(this.showTab==true){
            chkObj.select();
        }   
    },
	fileMenuCallback:function(v){
		if(this.ticker==null){
			Util.message(TEXT.QtIDRTicker);
			return;
		}
		var id = this.pId;
		var type = this.tickerType.toUpperCase();
		if(type=="XI"){
			Util.message(TEXT.QtIDRNotSupportIndex);
			return;
		}
		if(type=="FO"||type=="FE"||type=="FC"){
			id = this.secId;
		}
		SiteBuilder_firstLoadLoginPage();
		var self = this;
        if (STATIC_VAR.marketIndexSessionExists == false) {
            this.interval = setInterval(function(){
                if (self.i < 10) {
                    self.i++;
					if(STATIC_VAR.marketIndexSessionExists ==true){
						window.open("https://awrd.morningstar.com/SB/Data/GetIDRDetailReport.aspx?disclosure=10&universe=10&datasrc=AWD&stkprem=1&instid=SBDEMO&lang=en-US&tool=Screener&symbol="+id,"","toolbar=no, menubar=no, resizable=no,location=no, status=no");
						clearInterval(self.interval);
					}
                } else {
                    clearInterval(self.interval);
                }
            }, 1000);
        }else{
			window.open("https://awrd.morningstar.com/SB/Data/GetIDRDetailReport.aspx?disclosure=10&universe=10&datasrc=AWD&stkprem=1&instid=SBDEMO&lang=en-US&tool=Screener&symbol="+id,"","toolbar=no, menubar=no, resizable=no,location=no, status=no");
		}
	},
    changeOutSize:function(w,h,id){
        var parent = this.el.parent().parent();		
		
        w = w || parent.width();
        h = h || parent.height();
        
        //var top=this.detail?28:60;
        var top=this.showTab?60:this.$mainWrapHeight;
        
        var iw=w-top<0?0:w-top;
        var ih=h-top<0?0:h-top;        
        if (this.detail==false) {
            this.$subWrap.css({width:iw});
			if(this.curIframe){
	            ih=ih-this.curIframe.TOP;
	        }			
        }
        if(this.curIframe){
            this.curIframe.css({ width: w + "px",height:ih+this.curIframe.TOP+"px"});
        }
    },
    saveConfig:function(){
        var ticker=null;
        if(this.pId&&this.pId.length>0){
            ticker=this.pId;
        }else if(this.secId&&this.secId.length>0){
            ticker=this.secId;
        }else{
            ticker=this.ticker;
        }
        return {
            ticker:ticker,
			securityType:this.tickerType,
            secId:this.secId,
            tab:this.tabId,
            subtab:this.subTabId,
            detail:this.detail,
            showTab:this.showTab
        };
        //we can only return this.config
    },
    clear:function(){
        this.ticker='';
        for(var p in this){
            if(!p || p == 'clear'){continue;}
            this[p] = null;
            delete this[p];
        }
    },
	SetCookie:function(name,value,expiredays){
		var cookieStr=name+ "=" +escape(value);
		if(expiredays){
			var exdate=new Date();
			exdate.setDate(exdate.getDate()+expiredays);
			cookieStr+=";expires="+exdate.toGMTString();
		}
		cookieStr+=";path=/";
		cookieStr+=";domain=.morningstar.com";
		document.cookie=cookieStr;
	},
	generateSRT:function(){

		//?????????key
		var key = Math.round(Math.random()*(99999999-10000000) + 10000000);
		
		//key??????rkey
		var rkey=parseInt(key.toString().split("").reverse().join(""),10);
		
		//key??rkey?????xkey
		var xkey=key^rkey;

		//xkey????λ?????sum
		var sum=0;
		for(var i=xkey.toString().length;i>0;i--){
			sum+=xkey%10;   //???λ??
			xkey=parseInt(xkey/10);
		}
		
		//??key??sum???????
		return key.toString()+sum.toString();
	}
};